let Mytellphone = "";
window.onload = function(){
}

function Ipone() {
	//手机号验证
	const telephone = document.getElementById("telephone").value;
    Mytellphone = telephone;
	const reg1 =/^1([358][0-9]|4[579]|66|7[0135678]|9[89])[0-9]{8}$/;
	if (!reg1.test(telephone)) {
		phone.innerHTML="<img src='img/no.png' style='vertical-align: middle;'>";
	}
	else {
		phone.innerHTML = "<img src='img/yes.png' style='vertical-align: middle;'>";
	}
}
function npd(){
	const newpassword = document.getElementById("newpassword").value;
    const reg1 = /^\w$/;
	const reg2 = /^(?=.*[a-zA-Z])(?=.*\d)(?=.*[#@!~%^&*.])[a-zA-Z\d#@!~%^&*.]{6,}$/;
	if (!reg1.test(newpassword)){
		nepd.innerHTML="<img src='img/no.png' style='vertical-align: middle;'>";
		// nepd.innerHTML="<span style='color: red'>请输入正确格式的密码！</span>";
	}
	else {
		nepd.innerHTML = "<img src='img/yes.png' style='vertical-align: middle;'>";
	}
}
function opd(){
	const npdd = document.getElementById("newpassword").value;
	const againpassword = document.getElementById("againpassword").value;
	if (againpassword != npdd ){
		oepd.innerHTML="<img src='img/no.png'  style='vertical-align: middle;'>";
	}
	else{
		oepd.innerHTML="<img src='img/yes.png' style='vertical-align: middle;'>";
	}
}
/*修改密码*/
function sub(){
    const telp = document.getElementById("telephone").value;
	const aspd = document.getElementById("againpassword").value;
    const nspd = document.getElementById("newpassword").value;
    //const reg2 = /^(?=.*[a-zA-Z])(?=.*\d)(?=.*[#@!~%^&*.])[a-zA-Z\d#@!~%^&*.]{6,}$/;

    if(telp == ''||aspd == ''||nspd == ''){
        alert('请补全信息！');
        return false;
    }else if(aspd != nspd){
        alert('两次密码不同,请检查！');
        return false;
    }
    else if(telp != Mytellphone){   //需要与数据库电话绑定
        alert('与默认电话不同，请重新输入！')
        return false;
    }
    else {
        var flag = confirm("确定提交？");
        if(flag){
            $.ajax({
               url:"http://localhost:8080/Barbr/resetPwd",
               type:"post",
               cache:false,
                dataType:"text",
               data:{"tellphone":telp,"newpwd":nspd},
               success(data){
                   alert("修改成功!");
               } ,
               error(){
                   alert("请求失败");
               }
            });
        }
    }
}
